package com.adkfp.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.adkfp.utils.LayuiUtil;
import com.adkfp.bean.ADKDeptBean;
import com.adkfp.bean.ADKNetGroupBean;
import com.adkfp.bean.ADKUserInfoBean;
import com.adkfp.service.IADKDeptService;
import com.adkfp.service.IADKUserInfoService;
import com.adkfp.service.IADKUserPhotoService;

/**
 * class name:ADKUserInfoAction <BR>
 * class description: ADKUserInfo表的增删改查 <BR>
 * Remark: <BR>
 * @version 1.00 2019年01月03日
 * @author JACK)jackwei
 */
@Controller
@RequestMapping("aDKUserInfo")
public class ADKUserInfoAction {
	@Resource(name="aDKUserInfoService")
	private IADKUserInfoService aDKUserInfoService;
	@Resource(name="aDKUserPhotoService")
	private IADKUserPhotoService aDKUserPhotoService;
	@Resource(name="aDKDeptService")
	private IADKDeptService aDKDeptService;
	
  /**
 	* Method name: selectAll <BR>
 	* Description: 查询所有记录 <BR>
 	* Remark: <BR>
 	* @param bean
 	* @return  Object<BR>
 	*/
	@RequestMapping("selectAll")
	@ResponseBody
	public Object selectAll(ADKUserInfoBean bean) {
		List<ADKUserInfoBean> list = new ArrayList<>();
		list = aDKUserInfoService.findByCondition(bean);
		long count = aDKUserInfoService.findByConditionCount(bean);
		return LayuiUtil.data(count, list);
	}
	
	//用于人员权限的模糊查询
	@RequestMapping("selectAllc")
	@ResponseBody
	public Object selectAllc(ADKUserInfoBean bean) {
		List<ADKUserInfoBean> list = new ArrayList<>();
		list = aDKUserInfoService.cfindByCondition(bean);
		long count = aDKUserInfoService.cfindByConditionCount(bean);
		return LayuiUtil.data(count, list);
	}
	
	//用于权限组-人员的增加人员
	@RequestMapping("selectAllu")
	@ResponseBody
	public Object selectAllu(ADKUserInfoBean bean,String groupID) {
		System.out.println("----用于权限组-人员的增加人员---的groupid是"+groupID);
		List<ADKUserInfoBean> list = new ArrayList<>();
		bean.setGroupID(Integer.parseInt(groupID));
		list = aDKUserInfoService.ufindByCondition(bean);
		long count = aDKUserInfoService.ufindByConditionCount(bean);
		//return LayuiUtil.data(count, list);
		return list;
	}
	/**
	 * Method name: index <BR>
	 * Description: 转发到页面 <BR>
	 * Remark: <BR>
	 * @return  String<BR>
	 */
	@RequestMapping("index")
	public String index() {
		return "aDKUserInfo/tree";
	}
	
	@RequestMapping("index2")
	public String index2() {
		return "aDKUserInfo/selectuser";
	}
	
	@RequestMapping("index3")
	public String index3() {
		return "aDKUserInfo/select";
	}
	
	
	/*@RequestMapping("index4")
	public String index4() {
		return "aDKUserGroup/UserGroupTop";
	}*/
	
	
	/**
	 * Method name: index <BR>
	 * Description: 增加人员 <BR>
	 * Remark: <BR>
	 * @return  String<BR>
	 */
	@RequestMapping("insertUserInfo")
	@ResponseBody
	public void insertUserInfo(HttpServletRequest request,ADKUserInfoBean bean) {
		if(bean.getAutoid()!=null&&bean.getAutoid()!=0) {
			aDKUserInfoService.update(bean);
		}else {
			aDKUserInfoService.insert(bean);
		}
	}
	
	//用于修改页面(查找id)
		@RequestMapping("findId")
		public String findId(HttpServletRequest request,String autoid,ADKUserInfoBean bean) {
			if(autoid != null && !autoid.equals("")) {
				bean=aDKUserInfoService.findById(Integer.parseInt(autoid));
			}
			request.setAttribute("u",bean);
			return "aDKUserInfo/adduser";
		}
		
		
				@RequestMapping("findId2")
				public Object findId2(HttpServletRequest request,String depid,ADKUserInfoBean bean) {
					//System.out.println("呵呵呵呵呵----------------"+depid);
					bean.setDepid(depid);
					request.setAttribute("u",bean);
					return "aDKUserInfo/selectuser";
				}
				
				//用于人员权限管理
				@RequestMapping("findId3")
				public Object findId3(HttpServletRequest request,String depid,ADKUserInfoBean bean) {
					//System.out.println("呵呵呵呵呵----------------"+depid);
					bean.setDepid(depid);
					request.setAttribute("u",bean);
					return "aDKUserGroup/UserGroupTop";
				}
				
				@RequestMapping("select")
				@ResponseBody
				public Object select(ADKUserInfoBean bean,String depid) {
					List<ADKUserInfoBean> list = new ArrayList<>();
					bean.setDepid(depid);
					list = aDKUserInfoService.afindByCondition(bean);
					long count = aDKUserInfoService.afindByConditionCount(bean);
					return LayuiUtil.data(count, list);
				}
				
		//删除组织机构
		@RequestMapping("deleteUserInfo")
		@ResponseBody
		public void deleteUserInfo(String autoid) {
			aDKUserInfoService.delete(Integer.parseInt(autoid));
		}
		
		//查找所有部门的名称
		@RequestMapping("selectDpetName")
		@ResponseBody
		public Object selectDpetName(ADKDeptBean deptbean) {
			List<ADKDeptBean> list = new ArrayList<>();
			list = aDKDeptService.selectdpetname();
			return list;
		}
		
		//验证名称唯一(FMY)
		@RequestMapping("checkSname")
		@ResponseBody
		public Object checkSname(ADKUserInfoBean bean,HttpServletRequest request) {
			String userid=request.getParameter("userid");
			List<ADKUserInfoBean> list = new ArrayList<>();
			long count = aDKUserInfoService.checkSname(bean);
			return count;
		}
}